﻿
using System.Windows.Controls;
using System.Globalization;
namespace LFSRecord2.View.Validators
{
    public class ProjectLengthValidationRule : ValidationRule
    {
        public int MinLength { get; set; }
        public int MaxLength { get; set; }

        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            double projectLength;

            // Is port a whole number?
            if (!double.TryParse((string)value, out projectLength))
            {
                return new ValidationResult(false, "Not a number.");
            }

            // Is in range?
            if ((projectLength < MinLength) || (projectLength > MaxLength))
            {
                string msg = string.Format(CultureInfo.InvariantCulture, "Project length must be between {0} and {1}.", MinLength, MaxLength);
                return new ValidationResult(false, msg);
            }

            // Valid port
            return new ValidationResult(true, null);
        }
    }
}
